package org.example.t0526;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * 使用AtomicInteger保证原子性
 */
public class T6 {

    static AtomicInteger count = new AtomicInteger();
    public static void main(String[] args) {
        for(int j=1;j<=10;j++){
            new Thread(() ->{
                for(int i=1;i<=1000;i++){
                    count.incrementAndGet();
                }
                System.out.println(count);
            },"t" + j).start();
        }
    }
}
